
<template>
    <div>
        <main-view
            :dataList="getDataList"
            :currentPage="currentPage"
            :isNullData="isNullData"
            @changeTab="changeTab"
            @handleCurrentChange="handleCurrentChange"
            @handleSizeChange="handleSizeChange"
        ></main-view>
    </div>
</template>

<script>
import {baseUrl} from '../../http/baseUrl';
export default {
    name: "collection",
    components:{
        mainView: (resolve) =>require([ "./components/mainView",], resolve),
    },
    computed: {
        token(){
            return this.$store.getters.token;
        },
    },
    data() {
        return {
            isNullData:false,
            classType:1,
            getDataList:[],
            currentPage: {
                page: 1,
                size: 10,
                total: 0,
            },
            
        };

    },
    methods: {
        initDataList(){
            this.isNullData = false;
            this.getDataList = [];
            this.currentPage.page = 1;
            this.getRecord();
        },
        changeTab(index){
            this.classType = index;
            this.initDataList();
        },
        handleCurrentChange(val){
            this.currentPage.page = val;
            this.getRecord();
        },
        handleSizeChange(val){
            this.currentPage.size = val;
            this.getRecord();
        },
        getRecord(){
            let that = this;
            this.$http({
                method:'GET',
                headers:{
                    PageStart:this.currentPage.page-1,
                    PageOffset:this.currentPage.size,
                    ApiToken:this.token,
                },
                url:`${baseUrl.getBaseUrl()}/_md/lib/api/home/orders?is_pay=1&data_base_type=${this.classType}`,
            }).then(res=>{
                if (res.data.code == "0") {
                    that.currentPage.total = res.data.page.total;
                    let resData = res.data.data;
                    if(resData.length!=0){
                        that.getDataList = resData;
                        console.log(that.getDataList);
                    }else{
                        that.isNullData = true;
                    }
                } else {
                    if (res.code == '20401') {
                        that.toast.warning("登录失效,请重新登录!");
                        that.stringutils.clearData();
                        setTimeout(() => {
                            that.$router.push('/index');
                        }, 1000);
                        return false;
                    }
                    that.toast.error(res.data.message);
                }
            });
        },
    },
   
    created() {
        this.getRecord();
    },
    

};
</script>

<style lang="stylus" scoped>
 
        
</style>